<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Models\Admin\Role;

class RoleController extends Controller
{
    public function index(Request $request) {
		if($request->isMethod('post')){
			$param = $_POST;
			$limit = $param['pageSize'];
            $offset = ($param['pageNumber'] - 1) * $limit;
			$data['rows'] = Role::when($param['searchText'],function($query)use($param){
					$query->where('name','like',"%".$param['searchText']."%");
				})->skip($offset)->take($limit)->get()->toArray();
			$data['total'] = Role::when($param['searchText'],function($query)use($param){
					$query->where('name','like',"%".$param['searchText']."%");
				})->count();
			return ['code'=>1,'msg'=>'表格加载成功','data'=>$data];
		}
		return view("admin.role.index");
	}
}
